package com.tepth.maintenancesystem.adapter;

import android.content.Context;

import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;
import com.tepth.maintenancesystem.R;
import com.tepth.maintenancesystem.bean.VehicleObj;

import java.util.List;

/**
 * Created by LHQ on 2016/11/28.
 */

public class MyDataAdapter extends SuperBaseAdapter<VehicleObj> {

    public MyDataAdapter(Context context, List<VehicleObj> data) {
        super(context, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, VehicleObj item, int position) {
        holder.setText(R.id.vehicle_number, item.getVehicleNumber());
        holder.setText(R.id.vehicle_line, item.getVehicleLine());
        holder.setText(R.id.vehicle_time, item.getVehicleTime());
        holder.setExpanded(R.id.expandable_layout, item.isExpanded());
        if (item.getVehicleType().equals("0")) {
            holder.setBackgroundResource(R.id.img_vehicle, R.drawable.vehicle_yellow);
        } else if (item.getVehicleType().equals("1")) {
            holder.setBackgroundResource(R.id.img_vehicle, R.drawable.vehicle_purple);
        } else if (item.getVehicleType().equals("2")) {
            holder.setBackgroundResource(R.id.img_vehicle, R.drawable.vehicle_red);
        } else if (item.getVehicleType().equals("3")) {
            holder.setBackgroundResource(R.id.img_vehicle, R.drawable.vehicle_green);
        }
        if (item.getVehicleLevel() == "1") {
            holder.setVisible2(R.id.rl_vehicle_red, true);
            holder.setVisible2(R.id.rl_vehicle_orange, true);
            holder.setVisible2(R.id.rl_vehicle_yellow, true);
            holder.setAppCompatTextView(R.id.tv_vehicle_red, item.getVehicleLevelNumber() + "次");
        } else if (item.getVehicleLevel() == "2") {
            holder.setVisible2(R.id.rl_vehicle_red, false);
            holder.setVisible2(R.id.rl_vehicle_orange, true);
            holder.setAppCompatTextView(R.id.tv_vehicle_orange, item.getVehicleLevelNumber() + "次");
            holder.setVisible2(R.id.rl_vehicle_yellow, true);
        } else if (item.getVehicleLevel() == "3") {
            holder.setVisible2(R.id.rl_vehicle_red, false);
            holder.setVisible2(R.id.rl_vehicle_orange, false);
            holder.setAppCompatTextView(R.id.tv_vehicle_yellow, item.getVehicleLevelNumber() + "次");
            holder.setVisible2(R.id.rl_vehicle_yellow, true);
        } else if (item.getVehicleLevel() == "0") {
            holder.setVisible2(R.id.rl_vehicle_red, false);
            holder.setVisible2(R.id.rl_vehicle_orange, false);
            holder.setVisible2(R.id.rl_vehicle_yellow, false);
        }
    }

    @Override
    protected int getItemViewLayoutId(int position, VehicleObj item) {
        return R.layout.vehicle_item;
    }

}
